package graph.editor;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.awt.geom.RectangularShape;
import java.io.Serializable;

import automaton.State;
import automaton.StateImpl;

@SuppressWarnings("serial")
public class Vertex implements Serializable {
	RectangularShape shape;
	String label;
	State state;
	Color color;

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	private static final Point2D DELTA_LABEL = new Point(1, -1);

	Vertex(RectangularShape rs, String label) {
		this.shape = rs;
		this.label = label;
		this.state = new StateImpl(false, false);
	}

	public boolean contains(int x, int y) {
		return shape.contains(x, y);
	}

	void draw(Graphics2D g2) {
		g2.setColor(getColor());
		g2.fill(shape);
		g2.setColor(Color.BLACK);
		if (label != null) {
			Font font = new Font(g2.getFont().getName(), Font.ITALIC, 15);
			g2.setFont(font);
			g2.drawString(label, (int) (shape.getMaxX() + DELTA_LABEL.getX()),
					(int) (shape.getMinY() + DELTA_LABEL.getY()));
		}

	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	public String getLabel() {
		return this.label;
	}

}
